package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import org.cbg.btn.CBGSellBtn;
import org.cbg.until.TraslationTableRuleUntil;
import org.come.until.CutButtonImage;
import org.come.until.Util;

import com.tool.Document.InputNum;
import com.tool.Document.NumberDocument;
import com.tool.tcpimg.UIUtils;

 

/**
 * 我要卖 寄售金钱 面板
 * 
 * @author Administrator
 * 
 */
public class TraslationWantSentjishoujinqianJpanel extends JPanel implements InputNum{

    /** 图片,多选框 上架7天 , 指定ID购买 */
    private JLabel tupian, time, buyId;
    /**
     * 输入框 寄售银两,寄售价格(元，分), 确认价格(元， 分),单价,指定ID购买
     */
    private JTextField bidsilver, consignmentpriceYuan, criceconfirmationYuan, assignID;
    private JLabel univalent;
    private CBGSellBtn sendOk;

    private JScrollPane jScrollPane;
    private JTextArea area;

    public TraslationWantSentjishoujinqianJpanel() {
        this.setPreferredSize(new Dimension(760, 460));
        this.setOpaque(false);
        this.setLayout(null);


        /**
         * 图片设置
         */
        tupian = new JLabel();
        tupian.setBounds(124, 34, 53, 51);
        tupian.setOpaque(false);
        tupian.setIcon(CutButtonImage.getCBG(2, null, 49, 49));
        this.add(tupian);

        bidsilver = new JTextField();
        bidsilver.setBounds(582, 90, 140, 18);
        bidsilver.setBorder(null);
        bidsilver.setOpaque(false);
        bidsilver.setVisible(true);
        bidsilver.setForeground(Color.white);
        bidsilver.setCaretColor(Color.white);
        bidsilver.setFont(UIUtils.TEXT_FONT1);
        bidsilver.setDocument(new NumberDocument(bidsilver, 0, this));
        this.add(bidsilver);

        consignmentpriceYuan = new JTextField();
        consignmentpriceYuan.setBounds(582, 116, 96, 18);
        consignmentpriceYuan.setBorder(null);
        consignmentpriceYuan.setOpaque(false);
        consignmentpriceYuan.setVisible(true);
        consignmentpriceYuan.setForeground(Color.white);
        consignmentpriceYuan.setCaretColor(Color.white);
        consignmentpriceYuan.setDocument(new NumberDocument(consignmentpriceYuan, 7, this));
        this.add(consignmentpriceYuan);

        criceconfirmationYuan = new JTextField();
        criceconfirmationYuan.setBounds(582, 143, 96, 18);
        criceconfirmationYuan.setBorder(null);
        criceconfirmationYuan.setOpaque(false);
        criceconfirmationYuan.setVisible(true);
        criceconfirmationYuan.setForeground(Color.white);
        criceconfirmationYuan.setCaretColor(Color.white);
        criceconfirmationYuan.setDocument(new NumberDocument(criceconfirmationYuan, 7));
        this.add(criceconfirmationYuan);

        univalent = new JLabel();
        univalent.setBounds(582, 170, 70, 18);
        univalent.setBorder(null);
        univalent.setOpaque(false);
        univalent.setVisible(true);
        univalent.setForeground(Color.white);
        this.add(univalent);

        assignID = new JTextField();
        assignID.setBounds(530, 296, 125, 18);
        assignID.setBorder(null);
        assignID.setOpaque(false);
        assignID.setVisible(true);
        assignID.setForeground(Color.white);
        assignID.setCaretColor(Color.white);
        assignID.setDocument(new NumberDocument(assignID, 7));
        this.add(assignID);

        /**
         * 多选框设计72.28
         */
        time = new JLabel();
//        time.setBounds(510, 222 + 2, 15, 15);
        time.setOpaque(false);
        time.setBorder(null);
        time.setBackground(null);
        time.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", -1, -1));
        this.add(time);

        buyId = new JLabel();
        buyId.setBounds(510, 265 + 2, 15, 15);
        buyId.setOpaque(false);
        buyId.setBorder(null);
        buyId.setBackground(null);
        this.add(buyId);
        buyId.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (buyId.getIcon() == null) {
                    buyId.setIcon(CutButtonImage.getImage("skin/8100226/button/13.png", -1, -1));
                } else {
                    buyId.setIcon(null);
                }
            }
        });
        sendOk = new CBGSellBtn("inkImg/number/b4/qrjs.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, "", this);
        sendOk.setBounds(560, 375, 105, 33);
        this.add(sendOk);

        jScrollPane = new JScrollPane();
        area = new JTextArea();
        area.append("1、上架需要缴纳寄售价格的2%的仙玉;\n");
        area.append("2、寄售价格在100仙玉-100000000仙玉之间。\n");
        area.append("3、最多可以寄售100亿大话币。");
        area.setBounds(65, 0, 386, 108);
        area.setForeground(UIUtils.COLOR_cbg6);
        area.setFont(new Font("宋体", Font.PLAIN, 12));
        area.setOpaque(false);
        TraslationTableRuleUntil.TableModel(jScrollPane, area);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(30);
        jScrollPane.setBounds(2, 296, 406, 108);
        this.add(jScrollPane);

    }

    @Override
    public void upNum(){
        BigDecimal j1 = ((NumberDocument) bidsilver.getDocument()).getNum();
        BigDecimal j2 = ((NumberDocument) consignmentpriceYuan.getDocument()).getNum();
        if (j1.longValue() <= 0 || j2.longValue() <= 0) {
            univalent.setText(null);
            return;
        }
        j1 = j1.divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_DOWN);
        j1 = j1.divide(j2, 2, BigDecimal.ROUND_HALF_DOWN);
        univalent.setText(j1.toString());
    }
    @Override
    public boolean isChange(){
        return false;
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = new ImageIcon("inkImg/number/b4/dhbjs.png");
        }
        g.drawImage(icon.getImage(), 15, 28, 729, 389, this);
        Util.drawMoney(g, 582, 75);


    }

    public BigDecimal getJG() {
        BigDecimal j1 = ((NumberDocument) consignmentpriceYuan.getDocument()).getNum();
        BigDecimal j2 = ((NumberDocument) criceconfirmationYuan.getDocument()).getNum();
        if (j1.compareTo(j2) == 0) {
            return j1;
        }
        return null;
    }

    public BigDecimal getJB() {
        BigDecimal j1 = ((NumberDocument) bidsilver.getDocument()).getNum();
        if (j1.longValue() < 10000000 || j1.longValue() % 100000 != 0) {
            return null;
        }
        return j1;
    }

    public BigDecimal getJB1() {
        BigDecimal j1 = ((NumberDocument) bidsilver.getDocument()).getNum();
        if (j1.longValue() > 2000000000) {
            return null;
        }
        return j1;
    }

    public BigDecimal getZD() {
        if (buyId.getIcon() != null) {
            BigDecimal j1 = ((NumberDocument) assignID.getDocument()).getNum();
            return j1;
        }
        return new BigDecimal(0);
    }
    /** 清空 */
    public void qk() {
        bidsilver.setText(null);
        consignmentpriceYuan.setText(null);
        criceconfirmationYuan.setText(null);
        assignID.setText(null);
        univalent.setText(null);
    }
}
